home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ConsoleWindow.c
-
- Contains: Sample code for Language Analysis Manager.
-
- Version: Technology: System 8
- Release: Daruma Developer Release 1
-
- Copyright: 1998 by Apple Computer, Inc., all rights reserved
-
- Contact: daruma@apple.com
-
- */
-
-
- #include "ConsoleWindow.h"
-
- #include <Fonts.h>
- #include <Controls.h>
- #include <TextUtils.h>
- #include <TextEdit.h>
- #include <Resources.h>
-
- // ========================================================================================
- // Private definitions
- // ========================================================================================
- enum
- {
- kCWTextMargin = 4,
- kCWMaxTEWidth = 1280,
- kCMGrowMax = 0x7FFF,
- kCMHorizScrollUnit = 8,
- kCWSignature = 'cnsl'
- };
-
- // AdjustConsoleWindow()'s operands
- enum
- {
- kCWCreateWindow,
- kCWResizeWindow,
- kCWChangeAttribute,
- kCWInputText,
- kCWClearText
- };
-
- struct OpaqueConsoleWindowRec
- {
- WindowRecord windowRec;
- OSType signature;
- TEHandle textHandle;
- ControlRef vScroll;
- ControlRef hScroll;
- };
- typedef struct OpaqueConsoleWindowRec OpaqueConsoleWindowRec, *ConsoleWindowPtr;
-
-
- // ========================================================================================
- // Prototypes for private functions
- // ========================================================================================
-
- static OSStatus CreateConsoleWindowCommon( WindowRef window, StringPtr fontName, SInt16 fontSize, ConsoleWindowPtr console );
- static void GetTERect( WindowRef window, Rect *destRect, Rect *viewRect );
- static void GetScrollBarRect ( WindowRef window, Rect *vScrollRect, Rect *hScrollRect );
- static void AdjustViewRect ( TEHandle teH );
- static void AdjustConsoleWindow( ConsoleWindowPtr console, SInt16 operand );
- static void UpdateTEAttribute( ConsoleWindowPtr console, Boolean redraw );
- static SInt32 ConsoleWindowCStrLen( const char *str );
- static Boolean IsConsoleWindow( WindowRef window );
- static void DoConsoleWindowMouseDown( ConsoleWindowPtr console, EventRecord *theEvent, SInt16 partCode, Boolean *closed );
- static void DoConsoleWindowUpdate( ConsoleWindowPtr console );
- static void DoConsoleWindowActivate( ConsoleWindowPtr console, Boolean toActive );
- static void DoConsoleWindowGrow( ConsoleWindowPtr console, Point startPt );
- static void ResizeConsoleWindow( ConsoleWindowPtr console );
- static void DoConsoleWindowContent( ConsoleWindowPtr console, Point startPt );
- static pascal void MyVScrollFilter( ControlRef control, SInt16 part );
- static pascal void MyHScrollFilter( ControlRef control, SInt16 part );
-
-
- /******************************************************************************************/
- #pragma mark --------------------------
- #pragma mark • Public Functions
- #pragma mark --------------------------
-
- // ========================================================================================
- // GetNewConsoleWindow
- // ========================================================================================
- OSStatus
- GetNewConsoleWindow( SInt16 resID, WindowRef behind, StringPtr fontName,
- SInt16 fontSize, ConsoleWindowPtr *console )
- {
- OSStatus err;
- WindowRef window = NULL;
- ConsoleWindowPtr newConsole = NULL;
-
- newConsole = (ConsoleWindowPtr)NewPtrClear( sizeof( OpaqueConsoleWindowRec));
- if ( newConsole == NULL) { err = MemError(); goto errExit; }
-
- window = GetNewWindow( resID, &newConsole->windowRec, behind);
- if ( window == NULL) { err = ResError(); goto errExit; }
-
- err = CreateConsoleWindowCommon( window, fontName, fontSize, newConsole);
- if ( err != noErr) goto errExit;
-
- *console = newConsole;
- return noErr;
-
- errExit:
- if ( window != NULL) CloseWindow( window);
- if ( newConsole != NULL) DisposePtr( (Ptr)newConsole);
- *console = NULL;
- return err;
- }
-
- // ========================================================================================
- // NewConsoleWindow
- // ========================================================================================
- OSStatus
- NewConsoleWindow( const Rect *windRect, StringPtr title, Boolean visible,
- SInt16 wDefProcID, WindowRef behind, Boolean goAwayFlag, long refcon,
- StringPtr fontName, SInt16 fontSize, ConsoleWindowPtr *console )
- {
- OSStatus err;
- WindowRef window = NULL;
- ConsoleWindowPtr newConsole = NULL;
-
- newConsole = (ConsoleWindowPtr)NewPtrClear( sizeof( OpaqueConsoleWindowRec));
- if ( newConsole == NULL) { err = MemError(); goto errExit; }
-
- window = NewWindow( &newConsole->windowRec, windRect, title, visible, wDefProcID,
- behind, goAwayFlag, refcon);
- if ( window == NULL) { err = MemError(); goto errExit; }
-
- err = CreateConsoleWindowCommon( window, fontName, fontSize, newConsole);
- if ( err != noErr) goto errExit;
-
- *console = newConsole;
- return noErr;
-
- errExit:
- if ( window != NULL) CloseWindow( window);
- if ( newConsole != NULL) DisposePtr( (Ptr)newConsole);
- *console = NULL;
- return err;
- }
-
-
- // ========================================================================================
- // DisposeConsoleWindow
- // ========================================================================================
- void
- DisposeConsoleWindow( ConsoleWindowPtr console )
- {
- if ( console != NULL)
- {
- CloseWindow( GetWindowFromConsoleWindow( console));
- TEDispose( console->textHandle);
- DisposePtr( (Ptr)console);
- }
- }
-
-
- // ========================================================================================
- // ProcessConsoleWindowEvent
- // ========================================================================================
- Boolean
- ProcessConsoleWindowEvent( EventRecord *theEvent, Boolean *closed )
- {
- Boolean processEvent = false;
- WindowRef whichWindow;
- SInt16 partCode;
- ConsoleWindowPtr console;
-
- *closed = false;
-
- switch ( theEvent->what )
- {
- case mouseDown:
- partCode = FindWindow( theEvent->where, &whichWindow);
- console = GetConsoleWindowFromWindow( whichWindow);
- if ( console != NULL)
- {
- DoConsoleWindowMouseDown( console, theEvent, partCode, closed);
- processEvent = true;
- }
- break;
-
- case updateEvt:
- whichWindow = (WindowRef)theEvent->message;
- console = GetConsoleWindowFromWindow( whichWindow);
- if ( console != NULL)
- {
- DoConsoleWindowUpdate( console);
- processEvent = true;
- }
- break;
-
- case activateEvt:
- whichWindow = (WindowRef)theEvent->message;
- console = GetConsoleWindowFromWindow( whichWindow);
- if ( console != NULL)
- {
- DoConsoleWindowActivate( console, ( theEvent->modifiers & activeFlag) != 0);
- processEvent = true;
- }
- break;
-
- case osEvt:
- if ( ( (theEvent->message & osEvtMessageMask) >> 24) == suspendResumeMessage)
- {
- console = GetConsoleWindowFromWindow( FrontWindow());
- if ( console != NULL)
- {
- DoConsoleWindowActivate( console, (theEvent->message & resumeFlag) != 0);
- }
- }
-
- default:
- break;
- }
-
- return processEvent;
- }
-
-
- // ========================================================================================
- // SetConcoleWindowFont
- // ========================================================================================
- void
- SetConcoleWindowFont( ConsoleWindowPtr console, StringPtr fontName, Boolean redraw )
- {
- GrafPtr savePort;
- SInt16 fontNum;
- FontInfo fontInfo;
-
- GetPort( &savePort);
-
- GetFNum( fontName, &fontNum);
-
- SetPort( (WindowRef)console);
- TextFont( fontNum);
-
- GetFontInfo( &fontInfo);
- (*console->textHandle)->txFont = fontNum;
- (*console->textHandle)->fontAscent = fontInfo.ascent;
- (*console->textHandle)->lineHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
-
- UpdateTEAttribute( console, redraw);
-
- SetPort( savePort);
- }
-
-
- // ========================================================================================
- // SetConcoleWindowFontSize
- // ========================================================================================
- void
- SetConcoleWindowFontSize( ConsoleWindowPtr console, SInt16 fontSize, Boolean redraw )
- {
- GrafPtr savePort;
- FontInfo fontInfo;
-
- GetPort( &savePort);
-
- SetPort( (WindowRef)console);
- TextSize( fontSize);
-
- GetFontInfo( &fontInfo);
- (*console->textHandle)->txSize = fontSize;
- (*console->textHandle)->fontAscent = fontInfo.ascent;
- (*console->textHandle)->lineHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
-
- UpdateTEAttribute( console, redraw);
-
- SetPort( savePort);
- }
-
-
- // ========================================================================================
- // PutPStringConsoleWindow
- // ========================================================================================
- void
- PutPStringConsoleWindow ( ConsoleWindowPtr console, StringPtr theString )
- {
- SInt32 maxLength;
-
- maxLength = (*console->textHandle)->teLength;
-
- TESetSelect( maxLength, maxLength, console->textHandle);
- TEInsert( &theString[1], theString[0], console->textHandle);
-
- AdjustConsoleWindow( console, kCWInputText);
- }
-
-
- // ========================================================================================
- // PutCStringConsoleWindow
- // ========================================================================================
- void
- PutCStringConsoleWindow ( ConsoleWindowPtr console, const char *theString )
- {
- SInt32 maxLength;
-
- maxLength = (*console->textHandle)->teLength;
-
- TESetSelect( maxLength, maxLength, console->textHandle);
- TEInsert( theString, ConsoleWindowCStrLen( theString), console->textHandle);
-
- AdjustConsoleWindow( console, kCWInputText);
- }
-
-
- // ========================================================================================
- // ClearConsoleWindowContent
- // ========================================================================================
- void
- ClearConsoleWindowContent( ConsoleWindowPtr console )
- {
- SInt32 maxLength;
-
- if ( console != NULL)
- {
- maxLength = (*console->textHandle)->teLength;
-
- if ( maxLength != 0)
- {
- TESetSelect( 0, maxLength, console->textHandle); // select all
- TEDelete( console->textHandle);
- AdjustConsoleWindow( console, kCWClearText);
- }
- }
- }
-
-
- // ========================================================================================
- // GetConsoleWindowFromWindow
- // ========================================================================================
- ConsoleWindowPtr
- GetConsoleWindowFromWindow( WindowRef window )
- {
- if ( IsConsoleWindow( window))
- {
- return (ConsoleWindowPtr)window;
- }
- else
- {
- return NULL;
- }
- }
-
-
- // ========================================================================================
- // GetWindowFromConsoleWindow
- // ========================================================================================
- WindowRef
- GetWindowFromConsoleWindow( ConsoleWindowRef console )
- {
- return (WindowRef)console;
- }
-
-
- /******************************************************************************************/
- #pragma mark --------------------------
- #pragma mark • Private Functions
- #pragma mark --------------------------
-
- // ========================================================================================
- // CreateConsoleWindowCommon
- // ========================================================================================
- static OSStatus
- CreateConsoleWindowCommon( WindowRef window, StringPtr fontName,
- SInt16 fontSize, ConsoleWindowPtr console )
- {
- OSStatus err;
- GrafPtr savePort;
- Rect viewRect, destRect;
- Rect vScrollRect, hScrollRect;
- SInt16 fontNum;
-
- GetPort( &savePort);
- SetPort( window);
-
- GetFNum( fontName, &fontNum);
- TextFont( fontNum);
- TextSize( fontSize);
-
- //------------------------------------------------------------------------------
- // Initialize values
- //
- console->textHandle = NULL;
- console->vScroll = NULL;
- console->hScroll = NULL;
-
- //------------------------------------------------------------------------------
- // Create scroll bars
- //
- GetScrollBarRect( window, &vScrollRect, &hScrollRect);
-
- console->vScroll = NewControl( window, &vScrollRect, "\p", true, 0, 0, 0, scrollBarProc, 0L);
- if ( console->vScroll == NULL) { err = MemError(); goto errExit; }
-
- console->hScroll = NewControl( window, &hScrollRect, "\p", true, 0, 0, 0, scrollBarProc, 0L);
- if ( console->hScroll == NULL) { err = MemError(); goto errExit; }
-
- //------------------------------------------------------------------------------
- // Create and set TextEdit handle
- //
- GetTERect( window, &destRect, &viewRect);
- console->textHandle = TENew( &destRect, &viewRect);
- if ( console->textHandle == NULL) { err = MemError(); goto errExit; }
-
- // TEAutoView( true, console->textHandle); <3>
- TEDeactivate( console->textHandle);
-
- //------------------------------------------------------------------------------
- // Set signature
- //
- console->signature = kCWSignature;
-
- //------------------------------------------------------------------------------
- // Adjust each gadjet
- //
- AdjustConsoleWindow( console, kCWCreateWindow);
-
- SetPort( savePort);
-
- ShowWindow( window);
-
- return noErr;
-
- errExit:
- if ( console->textHandle != NULL) TEDispose( console->textHandle);
- if ( console->vScroll != NULL) DisposeControl( console->vScroll);
- if ( console->hScroll != NULL) DisposeControl( console->hScroll);
- SetPort( savePort);
- return err;
- }
-
-
- // ========================================================================================
- // GetTERect
- // ========================================================================================
- static void
- GetTERect( WindowRef window, Rect *destRect, Rect *viewRect )
- {
- Rect windowRect = window->portRect;
-
- InsetRect( &windowRect, kCWTextMargin, kCWTextMargin);
- windowRect.bottom -= 15;
- windowRect.right -= 15;
-
- if ( viewRect != NULL)
- {
- *viewRect = windowRect;
- }
-
- if ( destRect != NULL)
- {
- *destRect = windowRect;
- destRect->right = destRect->left + kCWMaxTEWidth;
- }
- }
-
-
- // ========================================================================================
- // GetScrollBarRect
- // ========================================================================================
- static void
- GetScrollBarRect( WindowRef window, Rect *vScrollRect, Rect *hScrollRect )
- {
- Rect windowRect = window->portRect;
-
- if ( vScrollRect != NULL)
- {
- SetRect( vScrollRect, windowRect.right - 15, windowRect.top - 1,
- windowRect.right + 1, windowRect.bottom - 14);
- }
-
- if ( hScrollRect != NULL)
- {
- SetRect( hScrollRect, windowRect.left - 1, windowRect.bottom - 15,
- windowRect.right - 14, windowRect.bottom + 1);
- }
- }
-
-
- // ========================================================================================
- // AdjustViewRect
- //
- // Update the TERec's view rect so that it is the greatest multiple of
- // the lineHeight that still fits in the old viewRect.
- // ========================================================================================
- static void
- AdjustViewRect( TEHandle teH )
- {
- (*teH)->viewRect.bottom = ( ( ( (*teH)->viewRect.bottom - (*teH)->viewRect.top)
- / (*teH)->lineHeight) * (*teH)->lineHeight)
- + (*teH)->viewRect.top;
- }
-
-
- // ========================================================================================
- // AdjustConsoleWindow
- // ========================================================================================
- static void
- AdjustConsoleWindow( ConsoleWindowPtr console, SInt16 operand )
- {
- SInt16 oldValue, oldMaxValue;
- SInt16 newValue, newMaxValue, lines;
- SInt16 deltaV, deltaH;
- TEHandle teH = console->textHandle;
-
- //------------------------------------------------------------------------------
- // Hide both controls
- //
- // HideControl( console->vScroll);
- // HideControl( console->hScroll);
-
- if ( operand == kCWCreateWindow || operand == kCWResizeWindow)
- {
- Rect viewRect;
- Rect vScrollRect, hScrollRect;
-
- GetTERect( (WindowRef)console, NULL, &viewRect);
- (*teH)->viewRect = viewRect;
- AdjustViewRect( teH);
-
- //------------------------------------------------------------------------------
- // Resize both scroll bars
- //
- GetScrollBarRect( (WindowRef)console, &vScrollRect, &hScrollRect);
-
- MoveControl( console->vScroll, vScrollRect.left, vScrollRect.top);
- SizeControl( console->vScroll, vScrollRect.right - vScrollRect.left,
- vScrollRect.bottom - vScrollRect.top);
-
- MoveControl( console->hScroll, hScrollRect.left, hScrollRect.top);
- SizeControl( console->hScroll, hScrollRect.right - hScrollRect.left,
- hScrollRect.bottom - hScrollRect.top);
-
- //------------------------------------------------------------------------------
- // Adjust horizontal scroll bars
- //
- oldValue = GetControlValue( console->hScroll);
- oldMaxValue = GetControlMaximum( console->hScroll);
-
- newMaxValue = kCWMaxTEWidth - ( (*teH)->viewRect.right - (*teH)->viewRect.left);
- if ( newMaxValue < 0 ) newMaxValue = 0;
- SetControlMaximum( console->hScroll, newMaxValue);
-
- newValue = (*teH)->viewRect.left - (*teH)->destRect.left;
- if ( newValue < 0 )
- newValue = 0;
- else if ( newValue > newMaxValue )
- newValue = newMaxValue;
-
- SetControlValue( console->hScroll, newValue);
- }
-
- //------------------------------------------------------------------------------
- // Update lines
- //
- lines = (*teH)->nLines;
- // since nLines isn’t right if the last character is a return, check for that case
- if ( *( *(*teH)->hText + (*teH)->teLength - 1) == '\n' )
- lines++;
-
- //------------------------------------------------------------------------------
- // Adjust vertical scroll bars
- //
- oldValue = GetControlValue( console->vScroll);
- oldMaxValue = GetControlMaximum( console->vScroll);
-
- newMaxValue = lines - ( ( (*teH)->viewRect.bottom - (*teH)->viewRect.top) / (*teH)->lineHeight);
- if ( newMaxValue < 0 ) newMaxValue = 0;
- SetControlMaximum( console->vScroll, newMaxValue);
-
- if ( operand == kCWInputText)
- {
- //
- // Show the last line while inputing text <3>
- //
- newValue = newMaxValue;
- }
- else
- {
- newValue = ( (*teH)->viewRect.top - (*teH)->destRect.top) / (*teH)->lineHeight;
- if ( newValue < 0 )
- newValue = 0;
- else if ( newValue > newMaxValue )
- newValue = newMaxValue;
- }
-
- SetControlValue( console->vScroll, newValue);
-
- //------------------------------------------------------------------------------
- // Show both controls
- //
- // ShowControl( console->vScroll);
- // ShowControl( console->hScroll);
-
- //------------------------------------------------------------------------------
- // Adjust TextEdit
- //
- deltaH = ( (*teH)->viewRect.left - (*teH)->destRect.left)
- - GetControlValue( console->hScroll);
-
- deltaV = ( (*teH)->viewRect.top - (*teH)->destRect.top)
- - ( GetControlValue( console->vScroll) * (*teH)->lineHeight);
-
- TEScroll( deltaH, deltaV, teH);
- }
-
-
- // ========================================================================================
- // UpdateTEAttribute
- // ========================================================================================
- static void
- UpdateTEAttribute( ConsoleWindowPtr console, Boolean redraw )
- {
- GrafPtr savePort;
- WindowRef window = GetWindowFromConsoleWindow( console);
-
- GetPort( &savePort);
- SetPort( window);
-
- AdjustConsoleWindow( console, kCWChangeAttribute);
-
- if ( redraw)
- {
- Rect viewRect;
-
- GetTERect( window, NULL, &viewRect);
- EraseRect( &viewRect);
- TEUpdate( &viewRect, console->textHandle);
- }
-
- SetPort( savePort);
- }
-
-
- // ========================================================================================
- // ConsoleWindowCStrLen
- // ========================================================================================
- static SInt32
- ConsoleWindowCStrLen( const char *str )
- {
- SInt32 len = -1;
-
- do
- {
- len++;
- }
- while ( *str++ );
-
- return( len );
- }
-
-
- // ========================================================================================
- // IsConsoleWindow
- // ========================================================================================
- static Boolean
- IsConsoleWindow( WindowRef window )
- {
- if ( window != NULL)
- {
- return ( ((ConsoleWindowPtr)window)->signature == kCWSignature);
- }
- else
- {
- return false;
- }
- }
-
-
- // ========================================================================================
- // DoConsoleWindowMouseDown
- // ========================================================================================
- static void
- DoConsoleWindowMouseDown( ConsoleWindowPtr console, EventRecord *theEvent,
- SInt16 partCode, Boolean *closed )
- {
- WindowRef window = GetWindowFromConsoleWindow( console);
-
- switch ( partCode )
- {
- case inContent:
- if ( window != FrontWindow())
- SelectWindow( window);
- else
- DoConsoleWindowContent( console, theEvent->where);
- break;
-
- case inDrag:
- DragWindow( window, theEvent->where, &qd.screenBits.bounds);
- break;
-
- case inGrow:
- DoConsoleWindowGrow( console, theEvent->where);
- break;
-
- case inGoAway:
- if ( TrackGoAway( window, theEvent->where))
- {
- *closed = true; // <2> caller should dispose window
- }
- break;
-
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox( window, theEvent->where, partCode))
- {
- GrafPtr savePort;
-
- GetPort( &savePort);
- SetPort( window);
-
- EraseRect( &window->portRect);
- ZoomWindow( window, partCode, window == FrontWindow());
- ResizeConsoleWindow( console);
-
- SetPort( savePort);
- }
- break;
-
- default:
- break;
- }
- }
-
-
- // ========================================================================================
- // DoConsoleWindowUpdate
- // ========================================================================================
- static void
- DoConsoleWindowUpdate( ConsoleWindowPtr console )
- {
- GrafPtr savePort;
- WindowRef window = GetWindowFromConsoleWindow( console);
-
- GetPort( &savePort);
- SetPort( window);
-
- BeginUpdate( window);
-
- EraseRect( &window->portRect);
- TEUpdate( &window->portRect, console->textHandle);
- DrawGrowIcon( window);
- DrawControls( window);
-
- EndUpdate( window);
-
- SetPort( savePort);
- }
-
-
- // ========================================================================================
- // DoConsoleWindowActivate
- // ========================================================================================
- static void
- DoConsoleWindowActivate( ConsoleWindowPtr console, Boolean toActive )
- {
- WindowRef window = GetWindowFromConsoleWindow( console);
-
- if ( toActive )
- {
- DrawGrowIcon( window);
- HiliteControl( console->vScroll, 0);
- HiliteControl( console->hScroll, 0);
- }
- else
- {
- DrawGrowIcon( window);
- HiliteControl( console->vScroll, 255);
- HiliteControl( console->hScroll, 255);
- }
- }
-
-
- // ========================================================================================
- // DoConsoleWindowGrow
- // ========================================================================================
- static void
- DoConsoleWindowGrow( ConsoleWindowPtr console, Point startPt )
- {
- WindowRef window = GetWindowFromConsoleWindow( console);
- Rect growRect;
- SInt32 growth;
-
- growRect.top = (*console->textHandle)->lineHeight * 10 + kCWTextMargin * 2;
- growRect.left = 200;
- growRect.bottom = kCMGrowMax;
- growRect.right = kCMGrowMax;
-
- growth = GrowWindow( window, startPt, &growRect);
-
- if ( growth != 0L)
- {
- SizeWindow( window, growth & 0x0000FFFF, ( growth >> 16) & 0x0000FFFF, true);
- ResizeConsoleWindow( console);
- }
- }
-
-
- // ========================================================================================
- // ResizeConsoleWindow
- // ========================================================================================
- static void
- ResizeConsoleWindow( ConsoleWindowPtr console )
- {
- GrafPtr savePort;
- WindowRef window = GetWindowFromConsoleWindow( console);
-
- GetPort( &savePort);
- SetPort( window);
-
- AdjustConsoleWindow( console, kCWResizeWindow);
- InvalRect( &window->portRect);
-
- SetPort( savePort);
- }
-
-
- // ========================================================================================
- // DoConsoleWindowContent
- // ========================================================================================
- static void
- DoConsoleWindowContent( ConsoleWindowPtr console, Point startPt )
- {
- GrafPtr savePort;
- WindowRef window = GetWindowFromConsoleWindow( console);
- Point localPt;
- SInt16 value, part, lineHeight;
- ControlRef targetControl;
- ControlActionUPP myTrackCntlUPP;
-
- GetPort( &savePort);
- SetPort( window);
-
- localPt = startPt;
- GlobalToLocal( &localPt);
-
- // Set control RefCon to use internal of filter proc
- SetControlReference( console->vScroll, (long)console);
- SetControlReference( console->hScroll, (long)console);
-
- part = FindControl( localPt, window, &targetControl);
-
- if ( targetControl == console->vScroll)
- myTrackCntlUPP = NewControlActionProc( MyVScrollFilter);
- else
- myTrackCntlUPP = NewControlActionProc( MyHScrollFilter);
-
- if ( part != 0)
- {
- switch ( part )
- {
- case kControlIndicatorPart:
- value = GetControlValue( targetControl);
- part = TrackControl( targetControl, localPt, NULL);
- if ( part != 0)
- {
- value -= GetControlValue( targetControl);
- if ( value != 0)
- {
- if ( targetControl == console->vScroll)
- {
- lineHeight = (*console->textHandle)->lineHeight;
- TEScroll( 0, value * lineHeight, console->textHandle);
- }
- else
- {
- TEScroll( value, 0, console->textHandle);
- }
- }
- }
- break;
-
- default:
- value = TrackControl( targetControl, localPt, myTrackCntlUPP);
- break;
- }
- }
-
- DisposeRoutineDescriptor( myTrackCntlUPP);
- SetPort( savePort);
- }
-
-
- // ========================================================================================
- // MyVScrollFilter
- // ========================================================================================
- static pascal void
- MyVScrollFilter( ControlRef control, SInt16 part )
- {
- SInt16 currentValue, maxValue, minValue;
- SInt16 updateDelta, lineHeight;
- ConsoleWindowPtr console;
- Rect viewRect;
-
- updateDelta = currentValue = GetControlValue( control);
- maxValue = GetControlMaximum( control);
- minValue = GetControlMinimum( control);
-
- console = (ConsoleWindowPtr)GetControlReference( control);
-
- lineHeight = (*console->textHandle)->lineHeight;
- GetTERect( (WindowRef)console, NULL, &viewRect);
-
- switch ( part )
- {
- case kControlPageUpPart:
- currentValue -= ( viewRect.bottom - viewRect.top) / lineHeight;
- if ( currentValue < minValue)
- currentValue = minValue;
- updateDelta -= currentValue;
- break;
-
- case kControlPageDownPart:
- currentValue += ( viewRect.bottom - viewRect.top) / lineHeight;
- if ( currentValue > maxValue)
- currentValue = maxValue;
- updateDelta -= currentValue;
- break;
-
- case kControlUpButtonPart:
- currentValue -= 1;
- if ( currentValue < minValue)
- currentValue = minValue;
- updateDelta -= currentValue;
- break;
-
- case kControlDownButtonPart:
- currentValue += 1;
- if ( currentValue > maxValue)
- currentValue = maxValue;
- updateDelta -= currentValue;
- break;
-
- default:
- return;
- }
-
- SetControlValue( control, currentValue);
- if ( updateDelta != 0)
- {
- TEScroll( 0, updateDelta * lineHeight, console->textHandle);
- }
- }
-
-
- // ========================================================================================
- // MyHScrollFilter
- // ========================================================================================
- static pascal void
- MyHScrollFilter( ControlRef control, SInt16 part )
- {
- SInt16 currentValue, maxValue, minValue;
- SInt16 updateDelta;
- ConsoleWindowPtr console;
- Rect viewRect;
-
- updateDelta = currentValue = GetControlValue( control);
- maxValue = GetControlMaximum( control);
- minValue = GetControlMinimum( control);
-
- console = (ConsoleWindowPtr)GetControlReference( control);
-
- GetTERect( (WindowRef)console, NULL, &viewRect);
-
- switch ( part )
- {
- case kControlPageUpPart:
- currentValue -= viewRect.right - viewRect.left;
- if ( currentValue < minValue)
- currentValue = minValue;
- updateDelta -= currentValue;
- break;
-
- case kControlPageDownPart:
- currentValue += viewRect.right - viewRect.left;
- if ( currentValue > maxValue)
- currentValue = maxValue;
- updateDelta -= currentValue;
- break;
-
- case kControlUpButtonPart:
- currentValue -= kCMHorizScrollUnit;
- if ( currentValue < minValue)
- currentValue = minValue;
- updateDelta -= currentValue;
- break;
-
- case kControlDownButtonPart:
- currentValue += kCMHorizScrollUnit;
- if ( currentValue > maxValue)
- currentValue = maxValue;
- updateDelta -= currentValue;
- break;
-
- default:
- return;
- }
-
- SetControlValue( control, currentValue);
- if ( updateDelta != 0)
- {
- TEScroll( updateDelta, 0, console->textHandle);
- }
- }
-
-
-